var app = getApp();
const util = require('../../utils/util')
    //Page Object
Page({
    data: {
        systemInfo: app.systemInfo,
        pageType: false, //true=图文，false=视频
        imageList: [
            { 'id': '1', 'src': '../../image/1.png' },
            { 'id': '1', 'src': '../../image/1.png' },
            { 'id': '1', 'src': '../../image/1.png' },
            { 'id': '1', 'src': '../../image/1.png' }
        ],
        usertype: false, //false=普通会员,true=VIP会员
        WorkInfo: {},
        videoUrl: null,
        advert: null,
    },
    GetQueryString(url) {
        var index = url.lastIndexOf("\?");
        let r = url.substring(index + 1, url.length);
        let strs = null
        if (r != null) {
            strs = r.split("=");
            return strs[1]
        }

    },
    goto: function(e) {
        console.log(e.currentTarget.dataset.id)
        let pageId = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '/pages/details/index?pageId=' + pageId
        });
    },
    getAdvert() {
        let _self = this
        util.getAdvert({ openId: app.openId }, function(res) {
            console.log(res)
            _self.setData({
                advert: res
            })
        })
    },
    time(e) {
        console.log(e.detail.currentTime)
        let times = e.detail.currentTime

    },
    getPage: function(articleId) {
        let _self = this

        util.postRequest('FinanceManage/rest/articleDetail.do', { openId: app.openId, type: '1', articleId: articleId }, function(data) {
            console.log(data)
            util.getStorage('userInfo', function(res) {
                console.log(res)
                if (data.bean.access_type == 1) {
                    _self.setData({
                        WorkInfo: data.bean,
                        videoUrl: data.bean.video
                    })
                } else if (data.bean.access_type == 2) {
                    if (res.type == 0) {
                        wx.showModal({
                            title: '会员提示',
                            content: '您还不是会员,点击确认开通会员',
                            success(res) {
                                if (res.confirm) {
                                    console.log('用户点击确定')
                                    wx.redirectTo({
                                        url: '/packageA/pages/purchaseVip/index'
                                    });
                                } else if (res.cancel) {
                                    console.log('用户点击取消')
                                    wx.navigateBack();
                                }
                            }
                        })
                    } else {
                        _self.setData({
                            WorkInfo: data.bean,
                            videoUrl: 'https://vd.yinyuetai.com/sh.yinyuetai.com/uploads/videos/common/C26F0168F58A34F6F8C5185AD94B5DAA.mp4'
                        })
                    }
                }
            })



        })
    },
    //options(Object)
    onLoad: function(options) {
        console.log(options.pageId)
        this.getPage(options.pageId)
        this.getAdvert()



        // console.log(this.data.WorkInfo)
        //     if (!this.data.usertype) {

        // wx.showModal({
        //     title: '会员提示',
        //     content: '您还不是会员,点击确认开通会员',
        //     success(res) {
        //         if (res.confirm) {
        //             console.log('用户点击确定')

        //             wx.redirectTo({
        //                 url: '/packageA/pages/purchaseVip/index'
        //             });
        //         } else if (res.cancel) {
        //             console.log('用户点击取消')
        //             wx.navigateBack();
        //         }
        //     }
        // })


        // }
    },
    onReady: function() {

    },
    onShow: function() {

    },
    onHide: function() {

    },
    onUnload: function() {

    },
    onPullDownRefresh: function() {

    },
    onReachBottom: function() {

    },
    onShareAppMessage: function() {

    },
    onPageScroll: function() {

    },
    //item(index,pagePath,text)
    onTabItemTap: function(item) {

    }
});